package customer.zspt.cn.customer.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by Administrator on 2018/8/18 0018.
 */

public class NetUtils {

    //wifi连接
    public static final int WIFINET = 1;
    //数据
    public static final int MOBILE = 0;
    //无连接
    public static final int NOTNET = -1;

    public static int getNetWorkState(Context context){
        //获得连接器管理者
        ConnectivityManager systemService =
                (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo();
        if(activeNetworkInfo!=null&&activeNetworkInfo.isConnected()){
            //如果是wifi
            if(activeNetworkInfo.getType()==ConnectivityManager.TYPE_WIFI){
                return WIFINET;
            }//移动数据
            else if(activeNetworkInfo.getType()==ConnectivityManager.TYPE_MOBILE){
                return MOBILE;
            }else{
                return NOTNET;
            }
        }
        return NOTNET;
    }

}
